<?php


namespace app\admin\controller;


use think\admin\Controller;

/**
 * 表格导出插件JS
 * Class Excel
 * @package app\admin\controller
 */
class Excel extends Controller
{

    /**
     * 表格导出demo
     * @auth true
     * @menu true
     */
    public function index()
    {
        $this->title = '表格导出demo';
        $this->fetch();
    }

    /**
     * 表格下载
     * @auth true
     * @menu true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function downExcel()
    {
        //定义表格首行标题,，注意与field查询字段 顺序一致
        $arr_title[] = [
            'username' => '用户',
            'action' => '操作对象',
            'node' => '操作节点',
            'geoip' => '登录ip',
            'create_at' => '更新时间',
        ];

        $query = $this->app->db->name('systemOplog')
            ->field(['username,action,node,geoip,create_at'])
            ->select()
            ->toArray();

        $this->success('success', array_merge($arr_title, $query));
    }

}